// ignore_for_file: import_of_legacy_library_into_null_safe

import 'package:flutter/material.dart';
import 'package:flutter_base_plugin/flutter_base_plugin.dart';
import 'package:flutter_base_plugin_example/page/home/vm/home_view_model.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
/// @author:  JoeKai
/// @date 2022/6/26 13:59
/// @explain：
class HomeBanner extends StatelessWidget{


  @override
  Widget build(BuildContext context) {
    HomeViewModel viewModel = context.watch<HomeViewModel>();
    return Stack(
      children: [
        Container(
          height: 150.h,
          width: double.infinity,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.only(
              bottomLeft: Radius.circular(20.r),
              bottomRight: Radius.circular(20.r),
            ),
            gradient: const LinearGradient(
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
                colors: [Colors.lightBlue, Colors.red]),
          ),
        ),
        AspectRatio(
          aspectRatio: 2 / 1,
          child: Padding(
            padding: EdgeInsets.all(15.h),
            child: ClipRRect(
              borderRadius: BorderRadius.all(
                Radius.circular(10.r),
              ),
              child: Swiper(
                autoplay: true,
                itemBuilder: (context, index) {
                  return InkWell(
                    onTap: () {
                      // CommonUtils.showToast(index);
                    },
                    child: Image.network(
                      viewModel.banner[index].replaceAll("\\", ""),
                      fit: BoxFit.fill,
                    ),
                  );
                },
                itemCount: viewModel.banner.length,
                pagination: SwiperPagination(
                  // 分页指示器
                    alignment: Alignment.bottomCenter,
                    // 位置 Alignment.bottomCenter 底部中间
                    margin: const EdgeInsets.fromLTRB(0, 0, 0, 5),
                    // 距离调整
                    builder: DotSwiperPaginationBuilder(
                      // 指示器构建
                        space: ScreenUtil().setWidth(5),
                        // 点之间的间隔
                        size: ScreenUtil().setWidth(10),
                        // 没选中时的大小
                        activeSize: ScreenUtil().setWidth(12),
                        // 选中时的大小
                        color: Colors.black54,
                        // 没选中时的颜色
                        activeColor: Colors.white)),
                // 选中时的颜色
                // 页面控制器 左右翻页按钮
                scale: 0.95, //
              ),
            ),
          ),
        )
      ],
    );
  }
}

